package tech.eyao.hs60x.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import tech.eyao.hs60x.annotation.Admin;
import tech.eyao.hs60x.dto.BaseResult;
import tech.eyao.hs60x.dto.ZoneDTO;
import tech.eyao.hs60x.service.ZoneService;
import tech.eyao.hs60x.utils.TokenUtils;

@Api("安全区")
@RestController
@RequestMapping("/zone")
public class ZoneController {
	@Autowired
	private ZoneService zoneService;
	
	@Admin
	@PostMapping("/set.do")
	@ApiOperation("设置")
	public BaseResult set(@ApiParam("主键ID 没有传0") long id,@ApiParam("手表账户ID")long watchId,@ApiParam("安全区名称")String zoneName,@ApiParam("经度") double longitude,
            @ApiParam(value = "纬度") double latitude,@ApiParam("半径")int r, 
            @ApiParam("地址")String address ) {
		return zoneService.set(id,TokenUtils.getUserId(),watchId,zoneName,longitude,latitude,r,address);
	}
	
	@PostMapping("/list.do")
	@ApiOperation(value = "列表", response=ZoneDTO.class)
	public BaseResult list(@ApiParam("手表账户ID")long watchId) {
		return zoneService.list(TokenUtils.getUserId(), watchId);
	}
	
	@Admin
	@PostMapping("/del.do")
	@ApiOperation("删除")
	public BaseResult delete(@ApiParam("手表账户ID")long watchId, @ApiParam("主键ID")long id) {
		return zoneService.delete(TokenUtils.getUserId(), watchId, id);
	}
}
